<template>
  <div>
    <ContentTitle :info="ctInfo" />

    <div class="SearchResultTab">
      <el-row class="flex aic">
        <el-col :span="2">月份选择：</el-col>
        <!-- 选择月份 -->
        <el-date-picker
          v-model="date"
          type="month"
          placeholder="选择月"
          value-format="yyyy-MM"
          class="month"
          size="small"
        >
        </el-date-picker>
        <download-excel
          :data="devListData"
          :fields="tableTitle"
          type="xlsx"
          worksheet="My Worksheet"
          name="使用记录.xlsx"
        >
          <el-button type="primary" size="mini">导出数据 </el-button>
        </download-excel>
      </el-row>

      <el-table :data="devListData" style="width: 100%">
        <el-table-column align="center" label="序号" type="index" width="120">
        </el-table-column>
        <el-table-column align="center" label="充值id" prop="id">
        </el-table-column>
        <el-table-column
          align="center"
          prop="cTime"
          label="日期"
          :formatter="formatTime"
        >
        </el-table-column>
        <el-table-column align="center" prop="amount" label="充值金额">
        </el-table-column>
        <el-table-column align="center" prop="desc" label="备注">
        </el-table-column>
      </el-table>
      <div class="flex jc-c pt-10 bg-fff pb-10">
        <!-- 分页按钮 -->
        <el-pagination
          background
          :hide-on-single-page="false"
          :current-page="currPage"
          @current-change="changePage"
          :total="total"
          :page-size="pageSize"
        >
        </el-pagination>
      </div>
    </div>
  </div>
</template>

<script>
import ContentTitle from "@/components/ContentTitle.vue";
import { $feeUsageList } from "@/api/index";
import moment from "moment";
export default {
  components: { ContentTitle },
  data() {
    return {
      currPage: 1,
      pageSize: 10,
      total: 20,
      date: "",
      moment,
      ctInfo: {
        type: "计费",
        text: "使用记录",
        msg: "统计当前账户每天消耗的消息额度总数，可查看历史月份的使用记录。",
      },
      // excel表头
      tableTitle: {
        充值id: "id",
        日期: "cTime",
        类型: "type",
        充值金额: "amount",
        备注: "desc",
      },
      // excel表数据
      devListData: [],
    };
  },
  created() {
    this.getList();
  },

  watch: {
    // 当选定月份时，date值变化，初始化页号，获取数据
    date() {
      // console.log(this.date);
      this.currPage = 1;
      this.getList();
    },
  },
  computed: {},

  methods: {
    changePage(page) {
      this.currPage = page;
      this.getList();
    },
    getList() {
      let currPage = this.currPage;
      let pageSize = this.pageSize;
      let date = this.date;
      $feeUsageList({ currPage, pageSize, date }).then((res) => {
        console.log(res);
        this.devListData = res.data;
        this.total = res.total;
        // this.json_data = res.data;
      });
    },
    exportDate() {},
  },
};
</script>

<style lang="less" scoped>
.SearchResultTab {
  margin-top: 10px;
  background: #fff;

  .el-row {
    align-items: center;
    padding: 20px 0;
  }
  .el-col-2 {
    display: flex;
    justify-content: flex-end;
    font-size: 13px;
    font-weight: 600;
  }
  .month {
    margin: 0 10px;
  }
}
</style>